package com.taxi.driver.common;

import android.content.Context;
import android.graphics.Typeface;

import com.mikepenz.iconics.typeface.IIcon;
import com.mikepenz.iconics.typeface.ITypeface;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;

/**
 * 功能描述：自定义"字体图片"
 */
public class DriverFont implements ITypeface {

    private static final String TTF_FILE = "driver.ttf";
    private static Typeface typeface = null;
    private static HashMap<String, Character> mChars;

    @Override
    public IIcon getIcon(String key) {
        return Icon.valueOf(key);
    }

    @Override
    public HashMap<String, Character> getCharacters() {
        if (mChars == null) {
            HashMap<String, Character> aChars = new HashMap<String, Character>();
            for (Icon v : Icon.values()) {
                aChars.put(v.name(), v.character);
            }
            mChars = aChars;
        }
        return mChars;
    }

    @Override
    public String getMappingPrefix() {
        return "pub";
    }

    @Override
    public String getFontName() {
        return "DriverFont";
    }

    @Override
    public String getVersion() {
        return "1.0.0";
    }

    @Override
    public int getIconCount() {
        return mChars.size();
    }

    @Override
    public Collection<String> getIcons() {
        Collection<String> icons = new LinkedList<String>();
        for (Icon value : Icon.values()) {
            icons.add(value.name());
        }
        return icons;
    }

    @Override
    public String getAuthor() {
        return "DriverFont";
    }

    @Override
    public String getUrl() {
        return "";
    }

    @Override
    public String getDescription() {
        return "";
    }

    @Override
    public String getLicense() {
        return "";
    }

    @Override
    public String getLicenseUrl() {
        return "";
    }

    @Override
    public Typeface getTypeface(Context ctx) {
        if (typeface == null) {
            try {
                typeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/" + TTF_FILE);
            } catch (Exception e) {
                return null;
            }
        }
        return typeface;
    }

    private enum Icon implements IIcon {

        public_pic_dagou('\ue800'),
        public_btn_fanye_left('\ue801'),
        public_btn_fanye_right('\ue802'),
        public_call('\ue803'),
        public_call2('\ue804'),
        public_car('\ue805'),
        public_close('\ue806'),
        public_daohang('\ue807'),
        public_guizeshuoming_shang('\ue808'),
        public_guizeshuoming_xia('\ue809'),
        public_icon_bill('\ue80a'),
        public_icon_bukejian('\ue80b'),
        public_icon_date('\ue80c'),
        public_icon_edit('\ue80d'),
        public_icon_explain('\ue80e'),
        public_icon_go_white('\ue80f'),
        public_icon_help('\ue810'),
        public_icon_jiajiaguize('\ue811'),
        public_icon_kejian('\ue812'),
        public_icon_map1('\ue813'),
        public_icon_map2('\ue814'),
        public_icon_message_close('\ue815'),
        public_icon_message('\ue816'),
        public_icon_mima('\ue817'),
        public_icon_money_go('\ue818'),
        public_icon_money('\ue819'),
        public_icon_phone('\ue81a'),
        public_icon_set('\ue81b'),
        public_icon_shenfenzheng('\ue81c'),
        public_icon_xitong_message('\ue81d'),
        public_jiaodan_icon_dacha('\ue81e'),
        public_map_dingwei('\ue81f'),
        public_myicon_back('\ue820'),
        public_nav_icon_back_gray('\ue822'),
        public_nav_icon_back_white('\ue823'),
        public_nav_logo_gray('\ue825'),
        public_nav_logo_light('\ue826'),
        public_nowifi('\ue827'),
        public_pic_go('\ue829'),
        public_pic_weixinzhifu('\ue82c'),
        public_pic_zhifubao('\ue82d'),
        public_plane_gray('\ue82f'),
        public_qiehuan('\ue830'),
        public_time_gray('\ue833'),
        public_time_white('\ue834'),
        public_wangjimima_go('\ue835'),
        public_zhifuxinxi_dacha('\ue836');

        Character character;

        Icon(char character) {
            this.character = character;
        }

        @Override
        public String getFormattedName() {
            return "{" + name() + "}";
        }

        @Override
        public String getName() {
            return name();
        }

        @Override
        public char getCharacter() {
            return character;
        }

        private static ITypeface typeface;

        @Override
        public ITypeface getTypeface() {
            if (typeface == null) return new DriverFont();
            return typeface;
        }

    }

}
